package com.hu.green.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.hu.green.commen.R;
import com.hu.green.entity.Recognition;
import com.hu.green.service.RecognitionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@CrossOrigin(value = "*")
@RequestMapping("/history")
public class RecognitionController {

    @Autowired
    private RecognitionService recognitionService;

    /**
     * 添加至识别历史
     * @param rec
     * @return
     */
    @PostMapping("/postH")
    public R postH(@RequestBody Recognition rec){
        recognitionService.save(rec);
        return R.success("已添加至识别历史");
    }

    /**
     * 获取识别历史
     * @param account
     * @return
     */
    @GetMapping("/{account}")
    public List<Recognition> getH(@PathVariable String account){
        LambdaQueryWrapper<Recognition> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Recognition::getAccount,account);
        List<Recognition> rec =  recognitionService.list(queryWrapper);
        return rec;
    }
}
